<template>
	<a-col :span="8">
		<a-form-item :label="label">
			<a-select
				v-if="name == 'clubID'"
				showSearch
				v-model="value"
				optionFilterProp="children"
				style="width: 100%"
				:showArrow="false"
				@search="fetchClub"
				:filterOption="filterOption"
				placeholder="请输入关键字进行搜索"
				allowClear
				@change="clubChange"
			>
				<a-select-option v-for="(item, index) in ClubList" :key="item.ID">{{ item.Name }}</a-select-option>
			</a-select>
			<a-select v-if="name == 'classID'" v-model="value" :allowClear="true" @search="fetchClass" placeholder="全部" optionFilterProp="children" showSearch @change="clubChange">
				<a-select-option v-for="(item, index) in ClassList" :key="index" :value="item.ID">{{ item.Name }}</a-select-option>
			</a-select>
			<a-select
			v-if="name == 'applyUserNo' || name == 'memberNo' || name == 'memberUserNo'"
			v-model="value"
				showSearch
				allowClear
				optionFilterProp="children"
				placeholder="请输入学号进行搜索"
				style="width: 100%"
				@search="fetchUser"
				:filterOption="filterOption"
				@change="clubChange"
			>
				<a-spin v-if="fetching" slot="notFoundContent" size="small" />
				<a-select-option v-for="(item, index) in userList" :key="item.UserNo">{{ item.UserNo }}&nbsp;|&nbsp;{{ item.Name }}</a-select-option>
			</a-select>
		</a-form-item>
	</a-col>
</template>

<script>
import { GetClubPageListCommon, GetClassList,GetUserList  } from '@/api/follow';
const data = [];
export default {
	props: {
		span: {
			type: Number,
			default: 8
		},
		name: String,
		label: String,
	},
	// watch: {
	// 	flowTypeID: function(flowTypeID) {}
	// },
	data() {
		return {
			ClubList: [],
			ClassList: [],
			userList:[],
			value: undefined,
			fetching:false
		};
	},
	mounted() {},
	methods: {
		filterOption(input, option) {
			return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0;
		},
		async fetchUser(value) {
			this.fetching = true;
			let myReg = /^[^a-zA-Z]+$/;
			if (value && value.length > 1) {
				let data = {};
				data.key = value;
				data.top = 20;
				let res = await GetUserList(data);
				this.fetching = false;
				this.userList = res.data.data;
			}
		},
		async fetchClass(value) {
			this.fetching = true;
			let myReg = /^[^a-zA-Z]+$/;
			if (value && value.length > 1) {
				let data = {};
				data.key = value;
				data.top = 20;
				data.departCode = this.$parent.$parent.form.getFieldValue('departCode')
				let res = await GetClassList(data);
				this.fetching = false;
				this.ClassList = res.data.data;
			}
		},
		async fetchClub(value) {
			let myReg = /^[^a-zA-Z]+$/;
			if (value && value.length > 1) {
				let data = {};
				data.key = value;
				data.departCode = this.$parent.$parent.form.getFieldValue('departCode')
				let res = await GetClubPageListCommon(data);
				this.ClubList = res.data.data;
			}
		},
		clubChange(e) {
			this.$emit('tap', this.name, e);
		}
	}
};
</script>

<style lang="less" scoped></style>
